package com.dao;

import com.entity.ClassGrade;
import com.entity.Major;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository("majorDao")
public interface MajorDao {
    @MapKey(value = "m_name")
    @Select("select * from major")
    Map<String, Map<String, String>> queryAll();

    @Select(value = "select * from major where college_id=#{college_id}")
    @Results({
            @Result(column = "mid", property = "id"),
            @Result(column = "m_name", property = "mName"),
            @Result(column = "college_id", property = "collegeId"),
            @Result(
                    column = "college_id",
                    property = "classGradeList",
                    javaType = List.class,
                    many = @Many(select = "com.dao.ClassGradeDao.queryByMid")
            )
    })
    Major queryByCollegeId(Long college_id);

    @Select("select * from major where mid=#{mid}")
    @Results({
            @Result(column = "mid", property = "id", id = true),
            @Result(column = "m_name", property = "mName"),
            @Result(column = "college_id", property = "collegeId")
    })
    Major queryById(Long mid);
}
